'use strict';


class PubSub {
    constructor() {
        this.sub = {};
    }

    publish(event, data) {
        let handlers = this.sub[event];
        for (var handler of handlers) {
            handler(data);
        }
    }

    subscribe(event, handler) {
        if (!this.sub[event]) this.sub[event] = [];
        this.sub[event].push(handler);
    }
}

let pubsub = new PubSub();

module.exports = pubsub;